package com.xiangyang.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiangyang.entity.Drugs;
import com.xiangyang.entity.MedicineGovern;
import com.xiangyang.entity.dto.Result;
import com.xiangyang.entity.vo.MedicineGovernPage;
import com.xiangyang.mapper.IDrugsMapper;
import com.xiangyang.mapper.IMedicineGovernMapper;
import com.xiangyang.service.IMedicineGovernService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MedicineGovernServiceImpl implements IMedicineGovernService {
    @Autowired
    private IMedicineGovernMapper medicineGovernMapper;
          @Override
    public Result selectDrugMange() {
        return Result.ok(medicineGovernMapper.selectDrugsMange());
    }

    @Override
    public int hidenDrugMange(Long drugId,Long isHedden) {
        int hidden = medicineGovernMapper.hidenDrugsMange(isHedden);
        if(hidden>0 && drugId!=null){
            return 1;
        }
        return 0;
    }

    @Override
    public Result Govern(MedicineGovernPage medicineGovernPage) {
         Page<MedicineGovern> page = new Page<>(medicineGovernPage.getPage(), medicineGovernPage.getSize());
         LambdaQueryWrapper<MedicineGovern> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.like(MedicineGovern::getGovernName, medicineGovernPage.getGovernName());
         return Result.ok(medicineGovernMapper.selectPage(page,queryWrapper));
    }
//    @Override
////    @OperationLog(title = "删除药品订单", businessType = "删除",oldDataMethod = "getData")
//    public String DeleteDrugMange(Long governId) {
//       if(governId==null){
//           return "请输入要删除的药品编号";
//       }
//       int deleteDrugs = medicineGovernMapper.deleteDrugsMange(governId);
//       return deleteDrugs>0?"删除成功":"删除失败";
//    }

    @Override
//    @OperationLog(title = "修改药品订单", businessType = "修改", oldDataMethod = "getData", newDataMethod = "getData")
    public Result UpdateDrugMange(Drugs drugs) {
        int updateDrugs = medicineGovernMapper.updateDrugsMange(drugs);
        if (updateDrugs == 0 &&
                drugs.getDrugNumbers() == null &&
                drugs.getDrugMakers() == null &&
                drugs.getDrugDepicts() == null &&
                drugs.getDrugPrices() == null &&
                drugs.getDrugTypes() == null &&
                drugs.getDrugNames() == null &&
                drugs.getDrugProductionDates() == null &&
                drugs.getDrugShelfSecond() == null) {
            return Result.error("修改失败");
        }
        return Result.ok("修改成功");
    }

}
